package com.cskaoyan.shopping.api;

import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemServiceResponse;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.mall.dto.ProductDetailServiceResponse;
import com.cskaoyan.shopping.service.IProductService;
import com.cskaoyan.shopping.service.ShoppingCartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther cskaoyan
 * @date 2022/8/24:14:56
 */
@RestController
public class OrderApiImpl {

    @Autowired
    IProductService productService;

    @Autowired
    ShoppingCartsService shoppingCartsService;

    @GetMapping(value = "/rpc/product/detail")
    ServiceCallResponse<ProductDetailDto> getProductDetail(@RequestParam("id") Long id) {
        ProductDetailDto productDetail = productService.getProductDetail(id);
        ServiceCallResponseUtil<ProductDetailDto> responseUtil = new ServiceCallResponseUtil<>();
        return responseUtil.ok(productDetail);
    }

    @DeleteMapping(value = "/rpc/cart/items")
    ClearCartItemServiceResponse clearCartItemByUserID(@RequestBody ClearCartItemRequest request){
        Long userId = request.getUserId();
        shoppingCartsService.deleteCartsChecked(userId);
        return new ClearCartItemServiceResponse();
    }


}
